﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PMS_Service.CODE
{
    public class WordDict
    {
        private PMSDataDataContext data = new PMSDataDataContext();
        private CompoundWord _CompoundWord;

        public CompoundWord CompoundWord
        {
            get { return _CompoundWord; }
            set { _CompoundWord = value; }
        }

        private StopWord _StopWord;

        public StopWord StopWord
        {
            get { return _StopWord; }
            set { _StopWord = value; }
        }

        private PrefixWord _PrefixWord;

        public PrefixWord PrefixWord
        {
            get { return _PrefixWord; }
            set { _PrefixWord = value; }
        }

        public WordDict()
        {
            _CompoundWord = new CompoundWord();
            _StopWord = new StopWord();
            _PrefixWord = new PrefixWord();
        }

        public List<CompoundWord> CompoundDict()
        {
            return data.CompoundWords.ToList();
        }

        public List<StopWord> StopDict()
        {
            return data.StopWords.ToList();
        }

        public List<PrefixWord> PrefixDict()
        {
            return data.PrefixWords.ToList();
        }

        public bool CheckContainCompoundWord(string value)
        {
            int count = data.CompoundWords.Where(d => d.CompoundWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public bool CheckContainCompoundWord(string value,List<CompoundWord> t)
        {
            int count = t.Where(d => d.CompoundWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public bool CheckContainStopWord(string value)
        {
            int count = data.StopWords.Where(d => d.StopWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public bool CheckContainStopWord(string value,List<StopWord> t)
        {
            int count = t.Where(d => d.StopWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public bool CheckContainPrefixWord(string value)
        {
            int count = data.PrefixWords.Where(d => d.PrefixWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public bool CheckContainPrefixWord(string value,List<PrefixWord> t)
        {
            int count = t.Where(d => d.PrefixWord1 == value).Count();
            if (count > 0)
                return true;
            return false;

        }

        public int? GetCompoundWordValue(string word)
        {
            int? value;
            if (data.CompoundWords.Where(d => d.CompoundWord1 == word).Count() > 0)
            {
                value = data.CompoundWords.Where(d => d.CompoundWord1 == word).Select(d => d.Value).First();
                return value;
            }
            else
            {
                return null;
            }
        }

        public int? GetCompoundWordValue(string word,List<CompoundWord> list)
        {
            int? value;
            if (list.Where(d => d.CompoundWord1 == word).Count() > 0)
            {
                value = list.Where(d => d.CompoundWord1 == word).Select(d => d.Value).First();
                return value;
            }
            else
            {
                return null;
            }
        }
    }
}
